package com.blog.mapper;

import com.blog.VO.CategoryDetailVO;
import com.blog.entity.Category;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import javax.annotation.Resource;
import javax.annotation.processing.SupportedSourceVersion;
import java.util.List;


/**
* @author 电脑小白
* @description 针对表【category】的数据库操作Mapper
* @createDate 2025-07-03 18:46:48
* @Entity com.blog.entity.Category
*/

public interface CategoryMapper {

    @Select("select id, category_name as categoryName from category")
    List<Category> get_category();

    @Select("select count(*) from category")
    Integer get_category_counts();


    @Select("select category_name as categoryName from category where id= #{categoryId}")
    String getcategorybyId(Integer categoryId);

    @Results({
            // 映射Category的主键ID
            @Result(property = "category.id", column = "id"),
            // 映射Category的名称
            @Result(property = "category.categoryName", column = "category_name"),
            // 映射文章数量
            @Result(property = "categoryCount", column = "categoryCount")
    })
    @Select("select a.*,count(b.id) as categoryCount from category a left join blog b on a.id = b.category_id group by a.id;")
    List<CategoryDetailVO> selectArticlesWithCategory();
}




